package cate.common.table.res.furniturecall.sheet;

import cate.common.table.ESheet;
import cate.common.table.res.furniturecall.row.FurnitureCallGroupsRow;
import cate.common.util.random.RWList;

import java.util.HashMap;
import java.util.Map;

/** 家具抽奖组池 */
public class FurnitureCallGroupsSheet extends ESheet<FurnitureCallGroupsRow> {

    @Override
    public String getSheetName() {
        return "盲盒开启奖池组";
    }

    private Map<Integer, Map<Integer, FurnitureCallGroupsRow>> groupMap = new HashMap<>();

    @Override
    protected void onRowCreated(FurnitureCallGroupsRow row) {
        Map<Integer, FurnitureCallGroupsRow> rwl = groupMap.computeIfAbsent(row.groupId, k -> new HashMap<>());
        rwl.put(row.id, row);
    }

    public Map<Integer, FurnitureCallGroupsRow> getGroupRows(int groupId){
        return groupMap.get(groupId);
    }

    /** 根据组随机出相应的家具 */
    public FurnitureCallGroupsRow randomHero(int groupId) {
        Map<Integer, FurnitureCallGroupsRow> map = groupMap.get(groupId);
        if (map == null) {
            return null;
        }
        RWList<FurnitureCallGroupsRow> rwList = new RWList<>();
        rwList.addAndSetup(map.values());
        return rwList.get();
    }
}
